package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CarOrderAfterSale;
import com.ruoyi.system.mapper.CarOrderAfterSaleMapper;
import com.ruoyi.system.service.ICarOrderAfterSaleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 退款售后Controller
 * 
 * @author ruoyi
 * @date 2024-09-09
 */
@RestController
@RequestMapping("/system/sale")
public class CarOrderAfterSaleController extends BaseController
{
    @Autowired
    private ICarOrderAfterSaleService carOrderAfterSaleService;
    
    @Autowired
    private CarOrderAfterSaleMapper carOrderAfterSaleMapper;

    /**
     * 查询退款售后列表
     */
    @PreAuthorize("@ss.hasPermi('system:sale:list')")
    @GetMapping("/list")
    public TableDataInfo list(CarOrderAfterSale carOrderAfterSale)
    {
        startPage();
        List<CarOrderAfterSale> list = carOrderAfterSaleService.selectCarOrderAfterSaleList(carOrderAfterSale);
        return getDataTable(list);
    }

    /**
     * 导出退款售后列表
     */
    @PreAuthorize("@ss.hasPermi('system:sale:export')")
    @Log(title = "退款售后", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarOrderAfterSale carOrderAfterSale)
    {
        List<CarOrderAfterSale> list = carOrderAfterSaleService.selectCarOrderAfterSaleList(carOrderAfterSale);
        ExcelUtil<CarOrderAfterSale> util = new ExcelUtil<CarOrderAfterSale>(CarOrderAfterSale.class);
        util.exportExcel(response, list, "退款售后数据");
    }

    /**
     * 获取退款售后详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:sale:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(carOrderAfterSaleService.selectCarOrderAfterSaleById(id));
    }

    /**
     * 新增退款售后
     */
    @PreAuthorize("@ss.hasPermi('system:sale:add')")
    @Log(title = "退款售后", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarOrderAfterSale carOrderAfterSale)
    {
        return toAjax(carOrderAfterSaleService.insertCarOrderAfterSale(carOrderAfterSale));
    }

    /**
     * 修改退款售后
     */
    @PreAuthorize("@ss.hasPermi('system:sale:edit')")
    @Log(title = "退款售后", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarOrderAfterSale carOrderAfterSale)
    {
        return toAjax(carOrderAfterSaleService.updateCarOrderAfterSale(carOrderAfterSale));
    }

    /**
     * 删除退款售后
     */
    @PreAuthorize("@ss.hasPermi('system:sale:remove')")
    @Log(title = "退款售后", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(carOrderAfterSaleService.deleteCarOrderAfterSaleByIds(ids));
    }
    
    /**
     * 获取退款售后详细信息
     */
    @PostMapping(value = "/getInfoOpen")
    public AjaxResult getInfoOpen(@RequestBody CarOrderAfterSale carOrderAfterSale)
    {
    	Long orderId=carOrderAfterSale.getOrderId();
        return success(carOrderAfterSaleMapper.selectByOrderId(orderId));
    }

    /**
     * 新增退款售后
     */
    @PostMapping("/addOpen")
    public AjaxResult addOpen(@RequestBody CarOrderAfterSale carOrderAfterSale)
    {
        return toAjax(carOrderAfterSaleService.insertCarOrderAfterSale(carOrderAfterSale));
    }
    
    /**
     * 查询退款售后列表
     */
    @PostMapping("/listOpen")
    public TableDataInfo listOpen(@RequestBody  CarOrderAfterSale carOrderAfterSale)
    {  
        startPage();
        List<CarOrderAfterSale> list = carOrderAfterSaleService.selectCarOrderAfterSaleList(carOrderAfterSale);
        return getDataTable(list);
    }

}
